﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Security.Cryptography;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Cuckoo.WP8.Resources;


namespace Cuckoo.WP8
{
	public partial class MainPage : PhoneApplicationPage
	{
		// Constructor
		public MainPage()
		{
			InitializeComponent();

			// Sample code to localize the ApplicationBar
			//BuildLocalizedApplicationBar();
		}

		private void btnPlay_Click(object sender, RoutedEventArgs e)
		{

			//Player mynewPage = new Player(); //newPage is the name of the newPage.xaml file
			//this.Content = mynewPage;
			NavigationService.Navigate(new Uri("/Player.xaml", UriKind.Relative));
		}

		private void btnGetId_Click(object sender, RoutedEventArgs e)
		{

			this.txtKey.Text = this.getDeviceID();
		}

		// Sample code for building a localized ApplicationBar
		//private void BuildLocalizedApplicationBar()
		//{
		//    // Set the page's ApplicationBar to a new instance of ApplicationBar.
		//    ApplicationBar = new ApplicationBar();

		//    // Create a new button and set the text value to the localized string from AppResources.
		//    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
		//    appBarButton.Text = AppResources.AppBarButtonText;
		//    ApplicationBar.Buttons.Add(appBarButton);

		//    // Create a new menu item with the localized string from AppResources.
		//    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
		//    ApplicationBar.MenuItems.Add(appBarMenuItem);
		//}

		private string getDeviceID()
		{
			byte[] token = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId"); 
			//string _deviceID = Convert.ToBase64String(deviceID);
			//return _deviceID;

			SHA1Managed hasher = new SHA1Managed();
			hasher.ComputeHash(token);
			//IBuffer hashed = hasher.HashData(hardwareId);

			return BitConverter.ToString(hasher.Hash).Replace("-", "").ToLowerInvariant();
		}
	}
}